home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 3.1 KB | 119 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPrfCnt.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifdef FW_PROFILE
-
- #ifndef FWPRFCNT_H
- #include "FWPrfCnt.h"
- #endif
-
- #include <string.h>
-
- #pragma segment FWDebug_PerformanceCounter
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CPerformanceCounter
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
- DWORD FW_CPerformanceCounter::gWinOverhead = (DWORD) -1;
- DWORD FW_CPerformanceCounter::gWinFreq = 0;
- #endif
-
- #ifdef FW_BUILD_MAC
- const long kMacMaxInterval = -60l * 1000l * 1000l; // microseconds: 1 minute
-
- long FW_CPerformanceCounter::gMacTMOverhead = -1;
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPerformanceCounter::FW_CPerformanceCounter
- //----------------------------------------------------------------------------------------
-
- FW_CPerformanceCounter::FW_CPerformanceCounter() :
- fResult(-1)
- {
- #ifdef FW_BUILD_WIN
- ::QueryPerformanceCounter(&fWinBegin);
-
- // Determine the overhead
- if (gWinOverhead == (DWORD) -1)
- {
- ::QueryPerformanceCounter(&fWinEnd);
- gWinOverhead = fWinEnd.LowPart - fWinBegin.LowPart;
-
- // Get the resolution
- LARGE_INTEGER liFreq;
- ::QueryPerformanceFrequency(&liFreq);
- gWinFreq = liFreq.LowPart;
-
- ::QueryPerformanceCounter(&fWinBegin);
- }
- #endif
- #ifdef FW_BUILD_MAC
- ::memset(&fMacTMTask, 0, sizeof(fMacTMTask));
- ::InsTime((QElemPtr) &fMacTMTask);
- ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
-
- // Determine the overhead
- if (gMacTMOverhead == -1)
- {
- ::RmvTime((QElemPtr) &fMacTMTask);
- gMacTMOverhead = fMacTMTask.tmCount - kMacMaxInterval;
-
- ::InsTime((QElemPtr) &fMacTMTask);
- ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
- }
-
- fMacIsInQueue = TRUE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPerformanceCounter::~FW_CPerformanceCounter
- //----------------------------------------------------------------------------------------
-
- FW_CPerformanceCounter::~FW_CPerformanceCounter()
- {
- #ifdef FW_BUILD_MAC
- if (fMacIsInQueue)
- ::RmvTime((QElemPtr) &fMacTMTask);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPerformanceCounter::EndCheckPoint
- //----------------------------------------------------------------------------------------
-
- void FW_CPerformanceCounter::EndCheckPoint()
- {
- #ifdef FW_BUILD_WIN
- ::QueryPerformanceCounter(&fWinEnd);
- fResult = fWinEnd.LowPart - fWinBegin.LowPart - gWinOverhead;
- #endif
- #ifdef FW_BUILD_MAC
- FW_ASSERT(fMacIsInQueue);
- ::RmvTime((QElemPtr) &fMacTMTask);
- fMacIsInQueue = FALSE;
- fResult = fMacTMTask.tmCount - kMacMaxInterval - gMacTMOverhead;
- #endif
- }
-
- #endif
-